/*
 * Copyright 2023, Haiku, Inc. All rights reserved.
 * Distributed under the terms of the MIT License.
 */
#ifndef _KERNEL_ARCH_LOONGARCH64_ARCH_CPU_H_
#define _KERNEL_ARCH_LOONGARCH64_ARCH_CPU_H_

#include <arch/loongarch64/arch_thread_types.h>
#include <kernel.h>

#define CPU_MAX_CACHE_LEVEL 8

struct cpu_topology_node
{
    uint32 id;
    uint32 level;
    uint32 type;
};

struct arch_cpu_info
{
    uint32 cpu_impl;
    uint32 cpu_part;
    uint32 cpu_variant;
    uint32 cpu_revision;
    uint32 cpu_features;
    cpu_topology_node topology[CPU_MAX_CACHE_LEVEL];
};

#ifdef __cplusplus
extern "C"
{
#endif

    struct iframe;

    extern status_t arch_cpu_preboot_init_percpu(kernel_args *args, int cpu);
    extern status_t arch_cpu_init_percpu(kernel_args *args, int cpu);
    extern status_t arch_cpu_init(kernel_args *args);
    extern status_t arch_cpu_init_post_vm(kernel_args *args);
    extern status_t arch_cpu_init_post_modules(kernel_args *args);
    extern void arch_cpu_sync_icache(void *address, size_t len);
    extern void arch_cpu_memory_read_barrier(void);
    extern void arch_cpu_memory_write_barrier(void);
    extern void arch_cpu_invalidate_TLB_range(addr_t start, addr_t end);
    extern void arch_cpu_invalidate_TLB_list(addr_t pages[], int num_pages);
    extern void arch_cpu_global_TLB_invalidate(void);
    extern void arch_cpu_user_TLB_invalidate(void);
    extern void arch_cpu_idle(void);
    extern void arch_cpu_dump_info(bool dumpAllCPUs);

#ifdef __cplusplus
}
#endif

#endif /* _KERNEL_ARCH_LOONGARCH64_ARCH_CPU_H_ */